package greedy;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ActivitySelection {

	static class Activity implements Comparable<Activity> {
		int f;
		int s;
		int index;

		public Activity(int index, int s, int f) {
			super();
			this.index = index;
			this.s = s;
			this.f = f;
		}

		@Override
		public int compareTo(Activity o) {
			if (f < o.f)
				return -1;
			else
				return 1;
		}

		@Override
		public String toString() {
			return "Activity [index=" + index + ", s=" + s + ", f=" + f + "]";
		}

	}

	Activity[] as = {new Activity(1, 1, 4),
			new Activity(2, 3, 5),
			new Activity(3, 0, 6),
			new Activity(4, 5, 7),
			new Activity(5, 3, 8),
			new Activity(6, 5, 9),
			new Activity(7, 6, 10),
			new Activity(8, 8, 11),
			new Activity(9, 8, 12),
			new Activity(10, 2, 13),
			new Activity(11, 12, 14)};
	List<Activity> lists = new ArrayList<Activity>();

	void greedy() {
		Arrays.sort(as);
		int f = Integer.MIN_VALUE;
		for (Activity a : as) {
			if (a.s >= f) {
				lists.add(a);
				f = a.f;
			}
		}
	}
	
	void output(){
		System.out.println(lists);
	}
	
	public static void main(String[] args) {
		ActivitySelection as = new ActivitySelection();
		as.greedy();
		as.output();
	}
}
